import request from '@/utils/request'

// 查询告警规则列表
export function listAlarmRule(query) {
  return request({
    url: '/energy/alarm/rule/list',
    method: 'get',
    params: query
  })
}

// 查询有效告警规则列表
export function getActiveAlarmRules() {
  return request({
    url: '/energy/alarm/rule/active',
    method: 'get'
  })
}

// 查询告警规则详细
export function getAlarmRule(ruleId) {
  return request({
    url: '/energy/alarm/rule/' + ruleId,
    method: 'get'
  })
}

// 新增告警规则
export function addAlarmRule(data) {
  return request({
    url: '/energy/alarm/rule',
    method: 'post',
    data: data
  })
}

// 修改告警规则
export function updateAlarmRule(data) {
  return request({
    url: '/energy/alarm/rule',
    method: 'put',
    data: data
  })
}

// 删除告警规则
export function delAlarmRule(ruleId) {
  return request({
    url: '/energy/alarm/rule/' + ruleId,
    method: 'delete'
  })
}

// 告警规则状态修改
export function changeAlarmRuleStatus(ruleId, status) {
  const data = {
    ruleId,
    status
  }
  return request({
    url: '/energy/alarm/rule/changeStatus',
    method: 'put',
    data: data
  })
}

// 校验规则名称
export function checkRuleNameUnique(ruleName, ruleId) {
  return request({
    url: '/energy/alarm/rule/checkRuleNameUnique',
    method: 'get',
    params: { ruleName, ruleId }
  })
}

// 导出告警规则
export function exportAlarmRule(query) {
  return request({
    url: '/energy/alarm/rule/export',
    method: 'post',
    params: query
  })
}

// ==================== 告警记录相关API ====================

// 查询告警记录列表
export function listAlarmRecord(query) {
  return request({
    url: '/energy/alarm/record/list',
    method: 'get',
    params: query
  })
}

// 查询最新告警记录
export function getRecentAlarms(limit = 10) {
  return request({
    url: '/energy/alarm/record/recent',
    method: 'get',
    params: { limit }
  })
}

// 查询告警记录详细
export function getAlarmRecord(recordId) {
  return request({
    url: '/energy/alarm/record/' + recordId,
    method: 'get'
  })
}

// 处理告警记录
export function processAlarmRecord(data) {
  return request({
    url: '/energy/alarm/record/process',
    method: 'put',
    data: data
  })
}

// 批量处理告警记录
export function batchProcessAlarmRecord(recordIds, processInfo) {
  return request({
    url: '/energy/alarm/record/batchProcess',
    method: 'put',
    data: {
      recordIds,
      processInfo
    }
  })
}

// 删除告警记录
export function delAlarmRecord(recordId) {
  return request({
    url: '/energy/alarm/record/' + recordId,
    method: 'delete'
  })
}

// 导出告警记录
export function exportAlarmRecord(query) {
  return request({
    url: '/energy/alarm/record/export',
    method: 'post',
    params: query
  })
}

// 获取告警统计信息
export function getAlarmStatistics(query) {
  return request({
    url: '/energy/alarm/statistics',
    method: 'get',
    params: query
  })
}